package cn.imnaer.service.rpc.userinfo.dao;

import cn.imnaer.database.BaseDao;
import cn.imnaer.database.define.DBConstant;
import cn.imnaer.service.persistence.model.FriendRelation;
import cn.imnaer.service.persistence.model.consts.FRIEND_RELATION;

import org.bson.BSONObject;
import org.bson.BasicBSONObject;

import java.util.List;

public class FriendRelationDaoImpl extends  BaseDao<FriendRelation>{

	private final static FriendRelationDaoImpl friendRelationActiveRecord = new FriendRelationDaoImpl();
	
	private FriendRelationDaoImpl(){
		this.dbSpaceName=DBConstant.SPACE.USER_INFO_SPACE;
		this.dbCollectionName=DBConstant.COLLECTION.FRIEND_RELATION_COLLECTION;
        this.primaryKey = FRIEND_RELATION.friendRelationId;
	}

    public static FriendRelationDaoImpl getInstance() {
        return FriendRelationDaoImpl.friendRelationActiveRecord;
    }

    public List<FriendRelation> findByUserId(String userId) {
        BasicBSONObject query = new BasicBSONObject();
        query.put(FRIEND_RELATION.userId, userId);
        query.put(FRIEND_RELATION.removed, false);

        List<FriendRelation> result = this.findAll(query, new BasicBSONObject(), null);
        return result;
    }

    public List<FriendRelation> findRealByUserId(String userId) {
        BSONObject query = new BasicBSONObject();
        query.put(FRIEND_RELATION.userId, userId);
        query.put(FRIEND_RELATION.eachOther, true);
        query.put(FRIEND_RELATION.removed, false);
        List<FriendRelation> result = this.findAll(query, new BasicBSONObject(),null);
        return result;
    }

    public FriendRelation findBySelfUserIdAndTargetUserId(String selfUserId, String targetUserId) {
        FriendRelation friendRelation = null;
        BasicBSONObject query = new BasicBSONObject();
        query.put(FRIEND_RELATION.userId, selfUserId);
        query.put(FRIEND_RELATION.friendUserId, targetUserId);     
        return this.findOne(query);
    }

	@Override
	protected String getDbSpaceName() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected String getDbCollectionName() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected String getPrimaryKey() {
		// TODO Auto-generated method stub
		return null;
	}
	
	
	

}
